home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / rfd12.arc / RFD.ASM < prev    next >
Assembly Source File  |  1990-06-09  |  7KB  |  191 lines

  1. ; ╔════════════════════════════════════════════════════════════════════════╗
  2. ; ║   Program     : RFD.ASM                           ║
  3. ; ║   Programmer : J. Stephen Redmond                       ║
  4. ; ║                                       ║
  5. ; ║      Syntax : RFD [d:]path [/Y]                       ║
  6. ; ║  Description : RFD removes the files and usbdirectory specified by the ║
  7. ; ║           path argument on the command line. RFD has two modes of ║
  8. ; ║           operation: 1> default command line mode, 2> batch mode. ║
  9. ; ║           1> Default - warning is issued and user must respond    ║
  10. ; ║                to proceed. (see warning message).       ║
  11. ; ║           2> Batch   - specify '/Y' argument on cmmand line.      ║
  12. ; ║                No warning will be issued and program will ║
  13. ; ║                attempt to remove director.           ║
  14. ; ║           Both modes of operation issue an ERRORLEVEL code upon   ║
  15. ; ║           termination as follows:                   ║
  16. ; ║                99 - Syntax error               ║
  17. ; ║                98 - Operator terminated           ║
  18. ; ║                             16 - Attempted to delete current directory ║
  19. ; ║                 5 - Protected file in subdirectory       ║
  20. ; ║                 3 - Path not found               ║
  21. ; ║                 0 - Successful completion           ║
  22. ; ╚════════════════════════════════════════════════════════════════════════╝
  23.  
  24.  
  25. ; ╔════════════════════════════════════════════════════════════════════════╗
  26. ; ║ Code marked [ADDED-JH] or [CHANGED-JH] has been altered from that pub- ║
  27. ; ║ lished in PC Magazine to add carry checking to properly handle errors  ║
  28. ; ║  The original code seems to function properly, but may return an error ║
  29. ; ║  code on sucessful completion.   -- Joe Harrington 11/26/87        ║
  30. ; ╚════════════════════════════════════════════════════════════════════════╝
  31. ; ╔════════════════════════════════════════════════════════════════════════╗
  32. ; ║ Code marked [ADDED-GM] or [CHANGED-GM] has been altered from that pub- ║
  33. ; ║ lished in PC Magazine to handle errors slightly different and add an   ║
  34. ; ║ additional Error Message for Error # 16.  -- Gary Meeker 11/30/87      ║
  35. ; ╚════════════════════════════════════════════════════════════════════════╝
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42. Code        segment para public 'code'
  43.         assume    cs:code
  44.  
  45.         org    0100h            ; .COM FILE, EXE2BIN
  46.  
  47. Begin:        jmp    start            ; terminate and stay resident
  48.         db    '(C) 1987, Ziff-Davis. By J. Stephen Redmond'
  49. Question    db    '** WARNING ** - All files will be deleted!',13,10
  50.         db    'Do you wish to proceed (Y/N) ? $'
  51. Msg1        db    'Syntax: RFD [d:]pathname [/Y]',13,10,'$'  ;erlvl 99
  52. Msg2        db    'Program terminated by operator',13,10,'$' ;erlvl 98
  53. Msg5            db      'Cannot remove current directory',13,10,'$' ;erlvl 16 [ADDED - GM]
  54. Msg3        db    'Protected files in subdirectory',13,10,'$';erlvl 05
  55. Msg4        db    'Specified path not found',13,10,'$'       ;erlvl 03
  56. Crlf        db    13,10,'$'
  57.  
  58. Pathname    db    64 dup (?)
  59. Wildcards    db    '\*.*',0
  60. Opmode_sw    db    1
  61.  
  62. Start        proc    near
  63.         cld
  64.         mov    si, 80h         ;point to path name length
  65.         mov    cl, byte ptr [si]    ;number of bytes on com line
  66.         cmp    cl, 4            ;need at least 4 char to omit
  67.         jae    Fix_up            ;     root directory
  68.         mov    al, 99            ; syntax error
  69.         jmp    Rfd_Exit
  70.  
  71. Fix_up:     sub    cl, 1            ;do not include leading space
  72.         xor    ch, ch            ;zero high half
  73.         push    cx            ;save length of pathname
  74.         mov    al, '/'                 ;search for switch indicator
  75.         mov    di, 82h         ;start search here
  76.         repne    scasb            ;scan the string
  77.         jcxz    Prompt            ;no switch, ask user if ok
  78.  
  79. Switch:     and    byte ptr [di], 5Fh    ;capitalize switch
  80.         cmp    byte ptr [di], 'Y'      ;is it the Y switch
  81.         jnz    Prompt            ;yes, skip prompt
  82.         pop    cx            ;get length of pathname
  83.         sub    cx, 2            ;adjust for switch length
  84.         push    cx            ;save adjusted length
  85.         mov    Opmode_sw, 0        ;set to batch mode
  86.         jmp    Set_Path
  87.  
  88. Prompt:     lea    dx, Question        ;query user
  89.         mov    ah, 9            ;service 9, print string
  90.         int    21h
  91.         mov    ah, 1            ;service 1, wait for keypress
  92.         int    21h            ;    and display it
  93.         and    al, 5Fh         ;captialize the response
  94.         cmp    al, 'Y'                 ;proceed confirmation?
  95.         jz    Set_Path        ;yes proceed
  96.         mov    al, 98            ;exit code
  97.         jmp    Rfd_Exit
  98.  
  99. Set_Path:    pop    cx            ;get path length
  100.         push    cx            ;save it again
  101.         mov    si, 82h         ;start move here
  102.         lea    di, Pathname        ;address of storage
  103.         repnz    movsb            ;move the pathname
  104.         mov    byte ptr [di], 0    ;make pathname ASCIIZ
  105.         lea    dx, Dta         ;new disk transfer address
  106.         mov    ah, 1Ah         ;service 1A - set dta
  107.         int    21h
  108.  
  109.         pop    bp            ;get length pathname
  110.         push    bp            ;save it again
  111.         lea    si, Wildcards        ;source sting
  112.         lea    di, pathname[bp]    ;destination string+offset
  113.         mov    cx, 5            ;byte count for move
  114.         repnz    movsb            ;move in wildcards
  115.  
  116.         lea    dx, Pathname        ;address pathname and wildcards
  117.         xor    cx, cx            ;zero attribute
  118.         mov    ah, 4Eh         ;Function 4E-Find first file
  119.         int    21h
  120.         jnc    Delete            ;[ADDED - JH]
  121.         cmp    al, 18            ;files not found [CHANGED-JH]
  122.                 je      remove
  123.         jmp    Rfd_Exit        ;[ADDED - JH]
  124.  
  125. Delete:     lea    si, dta[30]        ;where filename is stored
  126.         mov    cx, 0Dh         ;max 11 characters
  127.         lea    di, Pathname[bp+1]    ;after the '\'
  128.         repnz    movsb            ;store the filename in the
  129.         lea    dx, Pathname        ; full pathname
  130.         mov    ah, 41h         ;Function 41 - unlink
  131.         int    21h
  132.         jnc    Deletenxt        ;[ADDED - JH]
  133.         cmp    al, 5            ;al=5 means protected file
  134.                 je      Rfd_Exit
  135.  
  136. Deletenxt:    mov    ah, 4Fh         ;Function 4F-Find next
  137.         int    21h            ;  matching fIle
  138.         jnc    Delete            ;[ADDED - JH]
  139.         cmp    al, 18            ;no more files found
  140.                 jne     Rfd_Exit                ;[CHANGED - GM]
  141.  
  142. Remove:     pop    si            ;length of pathname
  143.         mov    Pathname[si], 0     ;make it ASCIIZ again
  144.         lea    dx, Pathname
  145.         mov    ah, 3Ah         ;Function 3A-Remdir
  146.         int    21h
  147.                 jc      Rfd_Exit                ;[ADDED - JH]
  148.         xor    ax, ax            ;[ADDED - JH]
  149.  
  150. Rfd_Exit:    cmp    Opmode_Sw, 0        ;0-Batch mode 1-Command
  151.         jz    Batch_mode
  152.         push    ax            ;save errorcode
  153.         lea    dx, Crlf        ;next line on display
  154.         mov    ah, 9            ;service 9-print string
  155.         int    21h
  156.         pop    ax            ;restore errorcode
  157.         cmp    al, 99            ;99-Incorrect syntax
  158.         jnz    E98
  159.         lea    dx, Msg1
  160.         jmp    Print
  161. E98:        cmp    al, 98            ;98-User terminated
  162.                 jnz     E16                     ;[CHANGED - GM]
  163.         lea    dx, Msg2
  164.         jmp    Print
  165. E16:            cmp     al, 16                  ;16-Cannot Delete Current Dir [ADDED - GM]
  166.                 jnz     E5                      ;[ADDED - GM]
  167.                 lea     dx, Msg5                ;[ADDED - GM]
  168.                 jmp     Print                   ;[ADDED - GM]
  169. E5:        cmp    al, 5            ;5-Protected file
  170.         jnz    E3
  171.         lea    dx, Msg3
  172.         jmp    Print
  173. E3:        cmp    al, 3            ;3-Path not found
  174.         jnz    Batch_mode
  175.         lea    dx, Msg4
  176.  
  177. Print:        push    ax            ;save errorcode
  178.         mov    ah, 9            ;service 9-print string
  179.         int    21h
  180.         pop    ax
  181.  
  182. Batch_mode:    mov    ah, 4Ch         ;service 4C-exit with code
  183.         int    21h
  184.  
  185. Start        endp
  186. Dta        label    byte            ;to store disk data
  187.  
  188. code        ends
  189.         end    Begin
  190.  
  191.